package com.meevle.commands {
	
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.meevle.business.SetDelegate;
	import com.meevle.events.CreateNewSetEvent;
	import com.meevle.lang.Messages;
	import com.meevle.model.ViewModelLocator;
	import com.meevle.vo.SetVO;
	import com.meevle.vo.UserVO;
	import com.meevle.error.ErrorHandler;
	import mx.rpc.events.FaultEvent;
	
	import mx.rpc.IResponder;
	
	public class CreateNewSetCommand implements ICommand, IResponder {
		
		private var setTemp:SetVO;
		
		public function CreateNewSetCommand() {
			
		}
		
		// ICommand interface method
		public function execute(event:CairngormEvent):void {
			var createNewSetEvent:CreateNewSetEvent = event as CreateNewSetEvent;
			var m_set:SetVO = createNewSetEvent.m_set;
			var delegate:SetDelegate = new SetDelegate(this);
			delegate.createSet(m_set);
		}
		
		//IResponder interface methods
		public function result(event:Object) : void {
				if(event.result == true) {
					ViewModelLocator.getInstance().createNewSetStatus = true;
					ViewModelLocator.getInstance().createNewSetError = null;
				} else {
					var error:Error = new Error("Sorry, the setname you selected is already in use");
					ViewModelLocator.getInstance().createNewSetError = error;
				}
				ViewModelLocator.getInstance().error = null;
		}
		
		public function fault(event:Object) : void {
			ErrorHandler.getInstance().handleError(event as FaultEvent);
		}	
	}
}